package com.lkd.http.controller;
import com.lkd.entity.OrderEntity;
import com.lkd.service.OrderService;
import com.lkd.vo.PayVO;
import com.lkd.wxpay.WxPayDTO;
import com.lkd.wxpay.WxPaySDKUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private WxPaySDKUtil wxPaySDKUtil;

    @PostMapping("/weixinPay")
    public String weixinPay(@RequestBody PayVO payVO){
        OrderEntity orderEntity = orderService.createOrder(payVO);
        //封装支付请求对象调用支付
        var wxPayDTO=new WxPayDTO();
        wxPayDTO.setBody(orderEntity.getSkuName());
        wxPayDTO.setOutTradeNo(orderEntity.getOrderNo());
        wxPayDTO.setTotalFee(orderEntity.getAmount().intValue());
        wxPayDTO.setOpenid(orderEntity.getOpenId());
        return wxPaySDKUtil.requestPay(wxPayDTO );
    }
}
